package com.leetcode.math;

public class Rotate {
    public static void main(String[] args) {
        int[][] matrix = {{1,2,3},{4,5,6},{7,8,9}};
        Rotate rotate = new Rotate();
        rotate.rotate(matrix);
    }

    public void rotate(int[][] matrix) {
        int[] tempArr = new int[matrix.length];
        int len = matrix.length;
        for (int row = 0; row < len/2; row++) {
            for (int col = row; col < len - row - 1; col++) {
                int tmp = matrix[row][col];
                matrix[row][col] = matrix[len - 1 - col][row];
                matrix[len - 1 - col][row] = matrix[len - 1 - row][len - 1 - col];
                matrix[len - 1 - row][len - 1 - col] = matrix[col][len - 1 - row];
                matrix[col][len - 1 - row] = tmp;
            }
        }
    }
}
